package com.eqdd.yiqidian.ui.mine.kanban;

import android.databinding.DataBindingUtil;
import android.support.v7.widget.LinearLayoutManager;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.eqdd.yiqidian.MyKanbanActivityCustom;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.adapter.slimadapter.SlimAdapterEx;
import com.eqdd.yiqidian.adapter.slimadapter.SlimInjector;
import com.eqdd.yiqidian.adapter.slimadapter.viewinjector.IViewInjector;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.bean.SecondBean;

import java.util.ArrayList;

public class MyKanbanActivity extends BaseActivity {
    private MyKanbanActivityCustom dataBinding;
    private ArrayList<Object> objects;

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_my_kanban);
        initTopTitleBar(View.VISIBLE, "我的看板");
    }

    @Override
    public void initData() {

        objects = new ArrayList<>();
        objects.add(new HeaderBean("执行达成率"));
        objects.add(new SecondBean("我的执行率","100%"));
        objects.add(new SecondBean("部门执行率","84%"));
        objects.add(new SecondBean("企业执行率","98%"));
        objects.add(new HeaderBean("绩效达成率"));
        objects.add(new SecondBean("我的达成率","87%"));
        objects.add(new SecondBean("部门平均达成率","75%"));
        objects.add(new SecondBean("企业平均达成率","85%"));
        objects.add(new HeaderBean("任务完成率"));
        objects.add(new SecondBean("我的完成率","95%"));
        objects.add(new SecondBean("部门平均完成率","68%"));
        objects.add(new SecondBean("企业平均完成率","75%"));
        objects.add(new HeaderBean("考勤排名"));
        objects.add(new SecondBean("部门考勤排名","1"));
        objects.add(new SecondBean("企业考勤排名","3"));
    }

    @Override
    public void setView() {

        dataBinding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        SlimAdapterEx slimAdapterEx = SlimAdapterEx.create()
                .register(R.layout.item_edit_title_type, new SlimInjector<HeaderBean>() {
            @Override
            public void onInject(HeaderBean data, IViewInjector injector) {
                injector.text(R.id.tv_top_title, data.getTitle())
                        .visible(R.id.rl_top);
            }
        })
                .register(R.layout.list_item_08, new SlimInjector<SecondBean>() {
                    @Override
                    public void onInject(SecondBean data, IViewInjector injector) {
                        injector.text(R.id.tv_upper_content,data.getFirst())
                                .with(R.id.tv_down_content,v->{
                                    TextView view= (TextView) v;
                                    view.setGravity(Gravity.CENTER_VERTICAL|Gravity.RIGHT);
                                    view.setText(data.getSecond());
                                });
                    }
                })
                .attachTo(dataBinding.recyclerView);
        slimAdapterEx.updateData(objects);

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {

        }
    }

    class HeaderBean{
        String title;

        public HeaderBean(String title) {
            this.title = title;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }
    }
}
